package tt.dz.order.vo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.lang.math.NumberUtils;

import tt.dz.order.dao.BaseDAOUtil;
import tt.dz.order.pojo.OrderItem;
import tt.dz.order.util.OrderConstant.OrderPayChannelCode;
import tt.dz.order.util.OrderConstant.OrderPayWay;
import tt.dz.order.util.OrderConstant.OrderStatus;

/**
 * 
 * 
 * @name 根据订单号查询订单项Vo
 * @author Anson
 * @version 1.0
 * @summary
 * @desc
 *
 */
public class OrderInfoVo {

	private static final String QUERY_ORDER_INFO = " SELECT T .orderNo,T.userId, T .relatedOrderNo, T.serviceNo, I. NAME AS mainServiceName, T .caculatedTotalPrice, T .payTypeCode as payType, T .payChannelCode as  thdPayChannel , 	T .status as statusCode, T .createTime, T .cardNo, T .attach FROM order_info T LEFT JOIN order_service_info I ON I.serviceno = T.serviceno WHERE T.orderno =:orderno ";

	/** 订单号 */
	private String orderNo;
	/** 订单号 */
	private String userId;
	/** 关联订单编号 */
	private String relatedOrderNo;
	/** 主服务编号 */
	private String serviceNo;
	/** 主服务名称 */
	private String mainServiceName;
	/** 实际应付的总价 */
	private BigDecimal caculatedTotalPrice;
	/** 支付类型 1 第三方实时支付 2 统付 3 企业支付 4 电子钱包支付 5 代付 6 线下卡 */
	private String payType;
	/** 第三方支付渠道名称 0 有贝先付 1 支付宝 2 微信支付 */
	private String thdPayChannel;
	/** 订单状态码 */
	private Integer statusCode;
	/** 订单状态 */
	private String status;
	/** 卡号 */
	private String cardNo;
	/** 创建时间 */
	private Date createTime;
	/**订单附加信息*/
	private String attach;
	/**
	 * 订单详细列表
	 */
	private List<OrderItem> itemDetials;

	public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getRelatedOrderNo() {
		return relatedOrderNo;
	}

	public void setRelatedOrderNo(String relatedOrderNo) {
		this.relatedOrderNo = relatedOrderNo;
	}

	public String getMainServiceName() {
		return mainServiceName;
	}

	public void setMainServiceName(String mainServiceName) {
		this.mainServiceName = mainServiceName;
	}

	public BigDecimal getCaculatedTotalPrice() {
		return caculatedTotalPrice;
	}

	public void setCaculatedTotalPrice(BigDecimal caculatedTotalPrice) {
		this.caculatedTotalPrice = caculatedTotalPrice;
	}

	public String getPayType() {
		return payType;
	}

	public void setPayType(String payType) {
		this.payType = payType;
	}

	public String getThdPayChannel() {
		return thdPayChannel;
	}

	public void setThdPayChannel(String thdPayChannel) {
		this.thdPayChannel = thdPayChannel;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Integer getStatusCode() {
		return statusCode;
	}

	public void setStatusCode(Integer statusCode) {
		this.statusCode = statusCode;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getServiceNo() {
		return serviceNo;
	}

	public void setServiceNo(String serviceNo) {
		this.serviceNo = serviceNo;
	}

	public List<OrderItem> getItemDetials() {
		return itemDetials;
	}

	public void setItemDetials(List<OrderItem> itemDetials) {
		this.itemDetials = itemDetials;
	}

	public String getAttach() {
		return attach;
	}

	public void setAttach(String attach) {
		this.attach = attach;
	}

	public OrderInfoVo() {
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj);
	}

	public static OrderInfoVo getOrderInfoVo(String orderNo) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orderno", orderNo);
		OrderInfoVo vo = BaseDAOUtil.queryForObject(QUERY_ORDER_INFO, params, OrderInfoVo.class);
		if(vo==null){
			return vo;
		}
		List<OrderItem> orderItems = OrderItem.getByOrderNo(orderNo);
		vo.setItemDetials(orderItems);
		// 转换相关的code为描述
		String payType = vo.getPayType();
		if (NumberUtils.isDigits(payType)) {
			vo.setPayType(OrderPayWay.getDesc(NumberUtils.toInt(payType)));
		}
		String payChannelCode = vo.getThdPayChannel();
		vo.setThdPayChannel(OrderPayChannelCode.getDesc(payChannelCode));
		Integer statusCode = vo.getStatusCode();
		vo.setStatus(OrderStatus.getDesc(statusCode));
		return vo;
	}
}
